$(function () {
    var guard_datagrid = $("#guard_datagrid");

    guard_datagrid.datagrid({
        fitColumns: true,
        fit: true,
        title:"保险产品",
        toolbar: '#',
        url: '/product/selectNomal.do',
        pagination: true,
        striped: true,
        rownumbers: true,
        singleSelect: true,
        columns: [[
            {title: '保险名称', field: 'name',align:'center', width: '100'},
            {title: '保险机构', field: 'promise' ,align:'center', width: '150', formatter: function (value, row, index) {
                    return value?value.name:"";
                }},
            {title: '保障年限', field: 'years' ,align:'center', width: '100'},
            {title: '保额', field: 'quota' ,align:'center', width: '100'},
            {title: '基本年费', field: 'cost' ,align:'center', width: '100'},
            {
                title: '不计免赔', field: 'deductible' ,align:'center', width: '100', formatter: function (value, row, index) {
                    return value ? "<font color='green'>是</font>" : "<font color='red'>否</font>"
                }
            }
        ]]

    })
    var methodObj = {
        //保存按钮
        submit: function () {
            console.log("1");
            //判断有没有选产品信息
            var data = guard_datagrid.datagrid('getSelected');
            if (!data) {
                $.messager.alert('温馨提示', "至少选择一条信息");
                return;
            }
            //选择了商品则传递product的id过去controller封装
            var productId = data.id;
          /* var classvalue = $("#carClasssification").textbox('getValue')
           var sizevalue = $("#carSize").textbox('getValue')
            console.log(classvalue);
            console.log(sizevalue);*/
            //提交到新建guard,controller里面封装
            $("#guard_form").form('submit',{
                url:"/guard/saveOrUpdate.do?product.id=" + productId,
                success:function(data){
                    data = $.parseJSON(data);
                    if (data.success) {
                        $.messager.alert('温馨提示', '保存成功', 'info', function () {
                            $("#guard_form").form("clear");
                            $("#guard_datagrid").datagrid("reload");
                        });
                    } else {
                        $.messager.alert('温馨提示', data.msg);
                    }
                }
            })
        }
    }
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    })



})









